package com.flute.haflute.net.messaging;

import org.apache.mina.core.session.IoSession;

/**
 * 封装session，使其可比较
 */
public class UdpComparableSession {

	private IoSession session;

	public UdpComparableSession(IoSession session) {
		this.session = session;
	}

	public IoSession getSession() {
		return session;
	}

	/*
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((session == null) ? 0 : session
				.getId()));
		return result;
	}

	/*
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UdpComparableSession other = (UdpComparableSession) obj;
		if (session == null) {
			if (other.session != null)
				return false;
		} else if (!(session.getId() == other.getSession().getId()))
			return false;
		return true;
	}

}
